/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2014-2019.
 * Description: header for kbox, mainly defining kbox device struct
 * Author: lichaoyue
 * Create: 2014-3-24
 */

#ifndef __KBOX_PRIVATE_H__
#define __KBOX_PRIVATE_H__

#include <linux/spinlock.h>

#define KBOX_DEBUG_TRACE_CONFIG 0
#if KBOX_DEBUG_TRACE_CONFIG
#define kbox_debug_trace() printk("\n*******[%s %d]\n", __FILE__, __LINE__)
#else
#define kbox_debug_trace()
#endif

/*
 *	kbox dev status:
 *				|-----------------------|
 *				V						|
 *		not format<---> fs ok<------>fs_error
 *				A		  A	         A
 *				|		  |			 |
 *				|		  |			 |
 *				|		  V			 |
 *				|--->  fault <--------
 *
 *	kbox status:
 *			maintain<------>working
 */
#define KBOX_DEV_STATUS_FS_OK		2
#define KBOX_DEV_STATUS_NOT_FORMAT	0
#define KBOX_DEV_STATUS_FAULT		3

#define KBOX_STATUS_SUCCESS	0
#define KBOX_STATUS_FAIL	(-1)

#define MSG_HEAD_SIZE sizeof(unsigned int)
#define MSG_END_SIZE sizeof(unsigned int)
#define MSG_ALIGN 4

/* device name max length */
#define KBOX_DEV_NAME_MAXLEN	32

/* only for kbox kernel modules */
#ifdef __KERNEL__

/*
 * kbox logbuf lib
 */
#define KBOX_LOG_BUF_CB_MAGIC	0xABC78DEF

#ifdef KBOX_SUPPORT_LOCKDEP
static inline void kbox_printk_lock(spinlock_t *lock, unsigned long *flags)
{
	raw_local_irq_save(*flags);
	lockdep_off();
	spin_lock_irq(lock);
}

static inline void kbox_printk_unlock(spinlock_t *lock, unsigned long *flags)
{
	spin_unlock(lock);
	lockdep_on();
	raw_local_irq_restore(*flags);
}

#else

static inline void kbox_printk_lock(spinlock_t *lock, unsigned long *flags)
{
	spin_lock_irqsave(lock, *flags);
}

static inline void kbox_printk_unlock(spinlock_t *lock, unsigned long *flags)
{
	spin_unlock_irqrestore(lock, *flags);
}

#endif

#define DDR_RAM_DEV_NAME    "ddrram"
#define DDR_RAM_DEVICE_PRIO  100

/* Control Block of an kbox device */
struct kbox_dev_des {
	char device_name[KBOX_DEV_NAME_MAXLEN];
	u32 size;
	u32 reserved0; /* mode, but now only one mode */
	u32 vm_flag;
	struct module *module;
	struct { /* only for devices in map mode */
		char *mapped_addr;
		int mapped_size;
		phys_addr_t phy;
	} map_op;

	void *private;
};

extern int kbox_register_device(struct kbox_dev_des *dev_desc);

extern int kbox_unregister_device(const char *name);

extern unsigned int kbox_default_reg_size;
extern unsigned int kbox_max_region_num;
#define KBOX_DEFAULT_REG_SIZE 65536
#define KBOX_DEFAULT_REG_NAME "panic"

/* version for kbox main init */
#define KBOX_MODUEL_VERSION                                "KBOX-0.1.1"

#endif

#endif

